package com.syg.FileUpload;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 文件上传与下载
 */
public class _03_Upload_DownLoad extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /**
         * 获取请求参数,区分不同的操作类型
         */
        String method = req.getParameter("METHOD");
        switch (method){
            case "upload":
                fileUpload(req,resp);//文件上传
                break;
            case "downLoad":
                downLoad(req,resp);//文件下载
                break;
            case "downList":
                downList(req,resp);//下载列表
                break;
            default:
                System.exit(0);//退出虚拟机,生产环境不可有这样的代码
        }
    }

    /**
     * 文件上传
     * @param request
     * @param response
     */
    private void fileUpload(HttpServletRequest request,HttpServletResponse response){

    }

    /**
     * 文件下载
     * @param request
     * @param response
     */
    private void downLoad(HttpServletRequest request,HttpServletResponse response){

    }

    /**
     * 下载列表
     * @param request
     * @param response
     */
    private void downList(HttpServletRequest request,HttpServletResponse response){}
}
